#pragma once

class CDynamicLibrary
{
private:

	HMODULE m_hLibrary;

public:

	CDynamicLibrary(LPCTSTR pszLibraryFileName) : m_hLibrary(NULL)
	{
		m_hLibrary = ::LoadLibrary(pszLibraryFileName);
	}

	virtual ~CDynamicLibrary(void)
	{
		if ( m_hLibrary )
			::FreeLibrary(m_hLibrary);
		m_hLibrary = NULL;
	}

	template < typename T >
	inline T GetProc(LPCSTR pszName) const
	{
		return m_hLibrary ? 
			T( ::GetProcAddress(m_hLibrary, pszName) ) : 
			T(NULL);
	}
};
